Imports Clo = Enhancements.Core.Logging
Imports Col = System.Collections
Imports Gen = System.Collections.Generic
Imports Iou = System.IO
Imports Ref = System.Reflection
Imports Reg = System.Text.RegularExpressions
Imports Sys = System
Imports Tex = System.Text
Imports Xsd = System.Xml.Schema
Imports W3c = System.Xml

Namespace Enhancements.Basic.Primitives
    ''' <summary>Represents a collection of date time format instances.</summary>
    <Serializable(), DebuggerStepThrough()> _
    Public NotInheritable Class DateTimeFormatCollection
        Implements Col.IEnumerable

        Private __Collection As Gen.List(Of DateTimeFormat) = New Gen.List(Of DateTimeFormat)

        ''' <summary>Initializes a DateTimeFormatCollection instance.</summary>
        Public Sub New()
        End Sub

        ''' <summary>Adds a format to the collection.</summary>
        ''' <param name="_format">Format to add.</param>
        ''' <exception cref="IsNullException">_format is null.</exception>
        ''' <exception cref="IsTrueException">The format is already in the collection.</exception>
        Public Sub Add(ByVal _format As DateTimeFormat)
            _format.IsNullNot("_format", True)
            __Collection.IsListContainingNot("__Collection", _format, "_format", False)

            __Collection.Add(_format)
        End Sub

        ''' <summary>Clears the collection.</summary>
        Public Sub Clear()
            __Collection.Clear()
        End Sub

        ''' <summary>Removes a format from the collection.</summary>
        ''' <param name="_format">Format to remove.</param>
        ''' <exception cref="IsNullException">_format is null.</exception>
        ''' <exception cref="IsTrueNotException">The format is not in the collection.</exception>
        Public Sub Remove(ByVal _format As DateTimeFormat)
            _format.IsNullNot("_format", True)
            __Collection.IsListContaining("__Collection", _format, "_format", False)

            __Collection.Remove(_format)
        End Sub

        ''' <summary>Removes a format from the collection.</summary>
        ''' <param name="_index">Index of the format to remove.</param>
        ''' <exception cref="IsInRangeNotException">_index is invalid.</exception>
        Public Sub RemoveAt(ByVal _index As Sys.Int32)
            __Collection.Count.IsInRange("__Collection.Count", 1, Sys.Int32.MaxValue, True)
            _index.IsInRange("_index", 0, __Collection.Count - 1, True)

            __Collection.RemoveAt(_index)
        End Sub

        ''' <summary>Gets a format of the collection.</summary>
        ''' <param name="_index">Index of the format to get.</param>
        ''' <exception cref="IsInRangeNotException">_index is invalid.</exception>
        Default Public ReadOnly Property Item(ByVal _index As Sys.Int32) As DateTimeFormat
            Get
                __Collection.Count.IsInRange("__Collection.Count", 1, Sys.Int32.MaxValue, True)
                _index.IsInRange("_index", 0, __Collection.Count - 1, True)

                Return __Collection(_index)
            End Get
        End Property

        ''' <summary>Gets the formats count in the collection.</summary>
        Public ReadOnly Property Count() As Sys.Int32
            Get
                Return __Collection.Count
            End Get
        End Property

        ''' <summary>Gets the instance IEnumerable.GetEnumerator implementation.</summary>
        ''' <returns> </returns>
        Public Function GetEnumerator() As Col.IEnumerator Implements Col.IEnumerable.GetEnumerator
            Return __Collection.GetEnumerator()
        End Function

    End Class
End Namespace
